home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / RCS / RoundRectangles,v < prev    next >
Encoding:
Text File  |  1995-06-12  |  14.1 KB  |  636 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  beta10:1.7;
  5. locks    death:1.8;
  6. comment  @# @;
  7.  
  8.  
  9. 1.8
  10. date     93.04.04.23.31.12;  author death;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     93.01.09.21.07.43;  author death;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     93.01.01.11.51.48;  author death;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     92.12.31.15.35.34;  author death;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     92.12.05.23.07.48;  author death;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     92.12.03.18.02.19;  author death;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     92.11.27.19.38.25;  author death;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     92.11.08.09.29.07;  author death;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.8
  55. log
  56. @Sun Apr  4 23:31:12 PDT 1993
  57. @
  58. text
  59. @%BEGIN ReoundRectangles
  60.  
  61. %%%%%%%%%%%%%
  62. %    Define the default values to be used for the width and height of the
  63. %    cuves on the corners of the round rectangles.
  64. %%%%%%%%%%%%%
  65. /ovWidth 0 def
  66. /ovHeight 0 def
  67.  
  68. %%%%%%%%%%%%%
  69. %    Name:    ovSize            [000B]
  70. %    Syntax:    width height ovSize -
  71. %    About:    Sets the width and height of curves on round-rectangle corners
  72. %%%%%%%%%%%%%
  73. /ovSize
  74. {
  75.     /ovHeight exch def
  76.     /ovWidth exch def
  77. }
  78. def
  79.  
  80. %%%%%%%%%%%%%
  81. %    Name:    buildRRpath
  82. %    Syntax:    t l b r buildRRpath -
  83. %    About:    Given a rectangle, build a round-rect path in that rect
  84. %            using the values of ovWidth and ovHeight.  This necessarily
  85. %            distorts userspace to get the ovaled corners.
  86. %            Note: This assumes there is a current path.  It does not
  87. %            create a new one because it is called 2ce by frameRRect
  88. %            Remove trapping for big oval sizes for pretty results
  89. %%%%%%%%%%%%%
  90. /buildRRpath
  91. {
  92.     /rightCoord exch def
  93.     /bottomCoord exch def
  94.     /leftCoord exch def
  95.     /topCoord exch def
  96.  
  97.     /startmatrix  matrix currentmatrix def
  98.     %
  99.     %    Compute half ovheight and half ovwith, trapping for (a) case when
  100.     %    width or height larger than corresponding rect dimension, and
  101.     %    (b) cases when ovwidth or ovheight is 0. In case of (b), we make
  102.     %    the half value non-zero, but very small.  We divide by this value
  103.     %    later, so a 0 value would be bad.  
  104.     %
  105.     ovHeight 0 le
  106.     { /halfheight .0001 def }
  107.     {
  108.         ovHeight bottomCoord topCoord sub gt
  109.             {/halfheight bottomCoord topCoord sub 2 div def}
  110.             {/halfheight ovHeight 2 div def}
  111.         ifelse
  112.     }
  113.     ifelse
  114.  
  115.     ovWidth 0 le
  116.     { /halfwidth .0001 def }
  117.     {
  118.         ovWidth rightCoord leftCoord sub gt
  119.             {/halfwidth rightCoord leftCoord sub 2 div def}
  120.             {/halfwidth ovWidth 2 div def}
  121.         ifelse
  122.     }
  123.     ifelse
  124.     %
  125.     %    Distort space properly for ovals, and compute where the
  126.     %    rectangle edges should be in this distorted space (so they
  127.     %    lie on the same screen locations despite distortion)
  128.     %
  129.     halfwidth halfheight gt
  130.     {
  131.         /unscale halfwidth halfheight div def
  132.         1 halfheight halfwidth div  scale
  133.         /radius halfwidth def
  134.         /newleft leftCoord def
  135.         /newright rightCoord def
  136.         /newtop topCoord unscale mul def
  137.         /newbottom bottomCoord unscale mul def
  138.     }
  139.     {
  140.         /unscale halfheight halfwidth div def
  141.         halfwidth halfheight div 1 scale
  142.         /radius halfheight def
  143.         /newleft leftCoord unscale mul  def
  144.         /newright rightCoord unscale mul def
  145.         /newtop topCoord def
  146.         /newbottom bottomCoord def
  147.     }
  148.     ifelse
  149.     %
  150.     %    Finally, draw the round rect using arct which draws both an
  151.     %    arced corner, as well as the edge to it.
  152.     %
  153.     newleft halfwidth add newtop moveto
  154.     newright newtop newright newbottom radius arct
  155.     newright newbottom newleft newbottom radius arct
  156.     newleft newbottom newleft newtop radius arct
  157.     newleft newtop newright newtop radius arct
  158.     closepath
  159.     startmatrix setmatrix
  160. }
  161. def
  162.  
  163.  
  164. %%%%%%%%%%%%%
  165. %    Name:    roundrectpath
  166. %    Syntax:    t l b r roundrectpath -
  167. %    About:    Provides a wrapper around buildRRpath so we can declare
  168. %            a newpath first.  Note that we define last* values here for
  169. %            all the routines below that call this.
  170. %%%%%%%%%%%%%
  171. /roundrectpath
  172. {
  173.     /lastright exch  def
  174.     /lastbottom exch  def
  175.     /lastleft exch def
  176.     /lasttop exch def
  177.  
  178.     newpath
  179.     lasttop lastleft lastbottom lastright buildRRpath
  180. }
  181. def
  182.  
  183. %%%%%%%%%%%%%
  184. %    Name:    frameRRect                [0040]
  185. %    Syntax:    t l b r frameRRect -
  186. %    About:    Frames the specified round rect. If the pen sizes are 1,
  187. %            stroke the path. Otherwise, build an inner path, and
  188. %            fill between them.
  189. %%%%%%%%%%%%%
  190. /frameRRect
  191. {
  192.     /lastright exch  def
  193.     /lastbottom exch  def
  194.     /lastleft exch def
  195.     /lasttop exch def
  196.     %
  197.     %    Do something if pen sizes > 0
  198.     %
  199.     penWidth 0 gt
  200.     penHeight 0 gt
  201.     and
  202.     {
  203.         gsave
  204.             penPattern usePattern
  205.             newpath
  206.             penWidth 1 eq
  207.             penHeight 1 eq
  208.             and
  209.             {
  210.                 lasttop lastleft lastbottom 1 sub  lastright 1 sub  buildRRpath
  211.                 stroke
  212.             }
  213.             {
  214.                 lasttop lastleft lastbottom lastright  buildRRpath
  215.                 %
  216.                 %    Compute parameters for inner edge of rrect frame.
  217.                 %    Note: we temporarily change ovWidth & ovHeight to
  218.                 %    produce aesthetically pleasing inner curves.
  219.                 %
  220.                 save
  221.                     /ovHeight ovHeight penHeight 2 mul sub def
  222.                     /ovWidth ovWidth penWidth 2 mul sub def
  223.                     lasttop penHeight add
  224.                     lastleft penWidth add
  225.                     lastbottom penHeight sub 
  226.                     lastright penWidth sub
  227.                     buildRRpath
  228.                     eofill
  229.                 restore
  230.             }
  231.             ifelse
  232.         grestore
  233.     }
  234.     if
  235. } def
  236.  
  237. %%%%%%%%%%%%%
  238. %    Name:    paintRRect            [0041]
  239. %    Syntax:    t l b r  paintRRect -
  240. %    About:    Fills the path of a round rectangle with the pen pattern
  241. %%%%%%%%%%%%%
  242. /paintRRect
  243. {
  244.     gsave
  245.         penPattern usePattern
  246.         roundrectpath
  247.         fill
  248.     grestore
  249. }
  250. def
  251.  
  252. %%%%%%%%%%%%%
  253. %    Name:    eraseRRect            [0042]
  254. %    Syntax:    t l b r  eraseRRect -
  255. %    About:    Fills the path of a round rectangle with the background pattern
  256. %%%%%%%%%%%%%
  257. /eraseRRect
  258. {
  259.     gsave
  260.         backPattern usePattern
  261.         roundrectpath
  262.         fill
  263.     grestore
  264. }
  265. def
  266.  
  267. %%%%%%%%%%%%%
  268. %    Name:    invertRRect            [0043]
  269. %    Syntax:    t l b r  invertRRect -
  270. %    About:    Calls roundrectpath to properly consume parameters.
  271. %            We don't know how to invert it, though, so don't.
  272. %%%%%%%%%%%%%
  273. /invertRRect
  274. {
  275.     gsave
  276.         roundrectpath
  277.     grestore
  278. } def
  279.  
  280. %%%%%%%%%%%%%
  281. %    Name:    fillRRect            [0044]
  282. %    Syntax:    t l b r  fillRRect -
  283. %    About:    Fills the path of a round rectangle with the fill pattern
  284. %%%%%%%%%%%%%
  285. /fillRRect
  286. {
  287.     gsave
  288.         fillPattern usePattern
  289.         roundrectpath
  290.         fill
  291.     grestore
  292. } def
  293.  
  294. %%%%%%%%%%%%%
  295. %    Name:    frameSameRRect            [0048]
  296. %    Syntax:    - frameSameRRect -
  297. %    About:    Frames the last roundrectangle used
  298. %%%%%%%%%%%%%
  299. /frameSameRRect
  300.     { lasttop lastleft lastbottom lastright frameRRect }
  301. def
  302.  
  303. %%%%%%%%%%%%%
  304. %    Name:    paintSameRRect            [0049]
  305. %    Syntax:    - paintSameRRect -
  306. %    About:    Paints the last roundrectangle used
  307. %%%%%%%%%%%%%
  308. /paintSameRRect
  309.     { lasttop lastleft lastbottom lastright paintRRect }
  310. def
  311.  
  312. %%%%%%%%%%%%%
  313. %    Name:    eraseSameRRect            [004A]
  314. %    Syntax:    - eraseSameRRect -
  315. %    About:    Erases the last roundrectangle used
  316. %%%%%%%%%%%%%
  317. /eraseSameRRect
  318.     { lasttop lastleft lastbottom lastright eraseRRect }
  319. def
  320.  
  321. %%%%%%%%%%%%%
  322. %    Name:    invertSameRRect            [004B]
  323. %    Syntax:    - invertSameRRect -
  324. %    About:    Inverts the last roundrectangle used
  325. %%%%%%%%%%%%%
  326. /invertSameRRect
  327.     { lasttop lastleft lastbottom lastright invertRRect }
  328. def
  329.  
  330. %%%%%%%%%%%%%
  331. %    Name:    fillSameRRect            [004C]
  332. %    Syntax:    - fillSameRRect -
  333. %    About:    Fills the last roundrectangle used
  334. %%%%%%%%%%%%%
  335. /fillSameRRect
  336.     { lasttop lastleft lastbottom lastright fillRRect }
  337. def
  338.  
  339. %END RoundRectangles
  340. @
  341.  
  342.  
  343. 1.7
  344. log
  345. @Sat Jan  9 21:07:43 PST 1993
  346. @
  347. text
  348. @@
  349.  
  350.  
  351. 1.6
  352. log
  353. @Fri Jan  1 11:51:48 PST 1993
  354. @
  355. text
  356. @@
  357.  
  358.  
  359. 1.5
  360. log
  361. @Thu Dec 31 15:35:34 PST 1992
  362. @
  363. text
  364. @@
  365.  
  366.  
  367. 1.4
  368. log
  369. @Sat Dec  5 23:07:47 PST 1992
  370. @
  371. text
  372. @d3 4
  373. a6 3
  374. %
  375. %    Define the default height and width for the ovals on round rectangles
  376. %
  377. d10 11
  378. d22 2
  379. a23 2
  380. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  381. %    utility:    buildRRpath
  382. d25 7
  383. a31 12
  384. %    Description:
  385. %        Given a rectangle, this routine actually constructs the path of a round rectangle
  386. %        with those bounds.  Because the corners are ovals (sometimes circles), it is
  387. %        necessary to play silly games distorting user space to get those ovals.
  388. %        this does so, and restores the CTM before returning, with the necessary
  389. %        closed path in place.
  390. %    Note:
  391. %        remove the trapping for oval sizes that are too big, and you can get
  392. %        some  cute results! =)
  393. %        I don't like the way I trap for 0 ovWidth or Height.  It seems inelegant, but my brain
  394. %        can't think of a better way right now.
  395. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  396. d34 2
  397. a35 2
  398.     /rightCoord exch 1 add def
  399.     /bottomCoord exch 1 add def
  400. d41 5
  401. a45 4
  402.     %    If ovHeight <= 0, then set the halfheight to a near-zero positive value
  403.     %    (a nicer algorithm might deal with 0's below) Otherwise, if the ovalheight
  404.     %    is > the height of the bounding rect, set the half(oval)height to be
  405.     %    half the rectangle height.  Otherwise use half ovHeight (unless is 0, then make it very small)
  406. d52 1
  407. a52 1
  408.             { /halfheight ovHeight 2 div def}
  409. d56 1
  410. a56 3
  411.     %
  412.     %    same as above, but with widith instead
  413.     %
  414. d62 1
  415. a62 1
  416.             { /halfwidth ovWidth 2 div def}
  417. d67 3
  418. a69 3
  419.     %    compute distortion needed to produce ovals of the right size.  Distort space, but
  420.     %    then *undistort* the edges (along the distorted axis) of our rectangle so they will
  421.     %    appear in the right places, even though the corners are scaled.
  422. a81 1
  423.         /scalefactor halfwidth halfheight div def
  424. d83 1
  425. a83 1
  426.         scalefactor 1 scale
  427. d92 2
  428. a93 1
  429.     %    Using arct, which will draws the leading line and then an arc,
  430. d106 2
  431. a107 3
  432.  
  433. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  434. %    utility:    roundrectpath
  435. d109 4
  436. a112 8
  437. %    Description:
  438. %        takes a rectangle (top left bottom right) and makes the current path a round
  439. %        cornered rectangle within these bounds.   Note that this is little more than
  440. %        a fancy wrapper aound buildRRpath.  (obviously).
  441. %    Weirdnesses:
  442. %        We use the lastrect globals for local variable use here...
  443. %    Note:
  444. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  445. d125 7
  446. a131 25
  447.  
  448. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  449. %    Opcode:    000B
  450. %    Name:    ovSize
  451. %    Syntax:    width height ovSize - 
  452. %    Description:
  453. %        Sets the width and height of the ovals to appear on round rectangles
  454. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  455. /ovSize
  456. {
  457.     /ovHeight exch def
  458.     /ovWidth exch def
  459. }
  460. def
  461.  
  462.  
  463. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  464. %    Opcode:    0040
  465. %    Name:    frameRRect
  466. %    Syntax:    t l b r  frameRRect - 
  467. %    Description:
  468. %        Frames the specified round rect.  Now, if the penwidth and height are zero, we just build
  469. %        the path and stroke it.  If not, however, we build an inner path and fill between them,
  470. %        producing the effect of the roundrect drawn by an irregularly shaped pen,as requested.
  471. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  472. d139 1
  473. a139 1
  474.     %    Do nothing if we've been asked to build with a 0 width or height pen
  475. d141 2
  476. a142 2
  477.     penWidth 0 ne
  478.     penHeight 0 ne
  479. a147 7
  480.             %
  481.             %    If our penwidth is not 1, then draw an inner and outer round rect.
  482.             %    otherwise, just uild one path and stroke it.  Note that in this case
  483.             %    we subtract 1 from the bottom and right coords because we are displaying
  484.             %    the NON-MODULAR knowledge that buildRRPath will turn around and add one
  485.             %    to these numbers, and we don't want them made bigger (so we are subtracting to compensate)
  486.             %
  487. d152 1
  488. a152 1
  489.                 lasttop lastleft lastbottom 1 sub lastright 1 sub  buildRRpath
  490. d158 3
  491. a160 6
  492.                 %    Compute parameters for inner rectangle (inner side of the RRect's thicknes)
  493.                 %    and pass to buildRRpath.  Then, do an eofil between the two we've build
  494.                 %    First, reduce the size of the ovals by the ammount of the pen dimensions.
  495.                 %    This APPEARS to be something like what the Mac is doing.  And, anyway, it
  496.                 %    is more aethetically pleasing.  =)  We do this by creating temporary
  497.                 %    ovHeigh and ovWidth values to fake buildRRpath out, and then resotre them later.
  498. d162 10
  499. a171 12
  500.                 /tempHeight ovHeight def
  501.                 /tempWidth ovWidth def
  502.                 /ovHeight ovHeight penHeight 2 mul sub def
  503.                 /ovWidth ovWidth penWidth 2 mul sub def
  504.                 lasttop penHeight add
  505.                 lastleft penWidth add
  506.                 lastbottom penHeight sub 
  507.                 lastright penWidth sub
  508.                 buildRRpath
  509.                 eofill
  510.                 /ovHeight tempHeight def
  511.                 /ovWidth tempWidth def
  512. d179 5
  513. a183 10
  514.  
  515.  
  516. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  517. %    Opcode:    0041
  518. %    Name:    paintRRect
  519. %    Syntax:    t l b r  paintRRect - 
  520. %    Description:
  521. %        Takes a rectangle, and passes it to roundrectpath which builds a path.
  522. %        Paints the resulting path.
  523. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  524. d194 5
  525. a198 9
  526.  
  527. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  528. %    Opcode:    0042
  529. %    Name:    eraseRRect
  530. %    Syntax:    t l b r  eraseRRect - 
  531. %    Description:
  532. %        Takes a rectangle, and passes it to roundrectpath which builds a path.
  533. %        erase the resulting path.
  534. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  535. d209 6
  536. a214 11
  537.  
  538. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  539. %    Opcode:    0043
  540. %    Name:    invertRRect
  541. %    Syntax:    t l b r  invertRRect - 
  542. %    Description:
  543. %        Takes a rectangle, and passes it to roundrectpath which builds a path.
  544. %        Then, do nothing.  Presumably we should invert it.  But, this isn't easy in
  545. %        PS, and I also haven't any examples on the Mac to prove to me how this
  546. %        actually works.  So.  This does nothing.
  547. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  548. d222 5
  549. a226 9
  550.  
  551. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  552. %    Opcode:    0044
  553. %    Name:    fillRRect
  554. %    Syntax:    t l b r  fillRRect - 
  555. %    Description:
  556. %        Takes a rectangle, and passes it to roundrectpath which builds a path.
  557. %        Fill the resulting path.
  558. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  559. d236 5
  560. a240 8
  561.  
  562. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  563. %    Opcode:    0048
  564. %    Name:    frameSameRRect
  565. %    Syntax:    -  frameSameRRect - 
  566. %    Description:
  567. %        frames, in the last rectangle used, the border of a round rectangle.
  568. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  569. d245 5
  570. a249 8
  571.  
  572. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  573. %    Opcode:    0049
  574. %    Name:    paintSameRRect
  575. %    Syntax:    -  paintSameRRect - 
  576. %    Description:
  577. %        paints, in the last rectangle used, the area of a round rectangle.
  578. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  579. d254 5
  580. a258 8
  581.  
  582. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  583. %    Opcode:    004A
  584. %    Name:    eraseSameRRect
  585. %    Syntax:    -  eraseSameRRect - 
  586. %    Description:
  587. %        erase, in the last rectangle used, the area of a round rectangle.
  588. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  589. d263 5
  590. a267 8
  591.  
  592. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  593. %    Opcode:    004B
  594. %    Name:    invertSameRRect
  595. %    Syntax:    -  invertSameRRect - 
  596. %    Description:
  597. %        in theory inverts the last rectangle used.
  598. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  599. d272 5
  600. a276 8
  601.  
  602. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  603. %    Opcode:    004C
  604. %    Name:    fillSameRRect
  605. %    Syntax:    -  fillSameRRect - 
  606. %    Description:
  607. %        What a surprise!  This fills the last round rectangle used!
  608. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  609. a281 1
  610.  
  611. @
  612.  
  613.  
  614. 1.3
  615. log
  616. @Thu Dec  3 18:02:19 PST 1992
  617. @
  618. text
  619. @@
  620.  
  621.  
  622. 1.2
  623. log
  624. @Fri Nov 27 19:38:25 PST 1992
  625. @
  626. text
  627. @@
  628.  
  629.  
  630. 1.1
  631. log
  632. @Sun Nov  8 09:29:07 PST 1992
  633. @
  634. text
  635. @@
  636.